package com.chainyoung.component_tmperson.ui.activity.cloudwallet;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.chainyoung.common.adpter.BaseFragmentAdapter;
import com.chainyoung.common.base.BaseActivity;
import com.chainyoung.common.di.AppComponent;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.ui.activity.cloudwallet.AddMyPurseActivity;
import com.chainyoung.component_tmperson.ui.fragment.MyPurseAddrListFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.chainyoung.component_tmperson.ui.fragment.MyPurseAddrListFragment.TYPE_CLOUD;
import static com.chainyoung.component_tmperson.ui.fragment.MyPurseAddrListFragment.TYPE_LOCAl;

public class MyPurseAddrActivity extends BaseActivity {


    @BindView(R2.id.tab_layout)
    SlidingTabLayout tabLayout;
    @BindView(R2.id.view_pager)
    ViewPager viewPager;

    private List<Fragment> fragmentList = new ArrayList<>();


    private List<String> titles = new ArrayList<>();

    private boolean isFromCloudSelect;

    private boolean isFromHdSelect;


    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    protected void initUI() {
        setCurrentTitle(R.string.tmperson_purse_addr);
        Drawable drawable = ContextCompat.getDrawable(mContext, R.mipmap.ic_add_addr);
        DrawableCompat.setTint(drawable, Color.parseColor("#061c69"));
        showAndSetBarRightIcon(drawable);
        isFromCloudSelect = getIntent().getBooleanExtra("selectCloudAddr", false);
        isFromHdSelect = getIntent().getBooleanExtra("selectLocalAddr", false);
        setTabLayout();
    }

    private void setTabLayout() {
        fragmentList.add(MyPurseAddrListFragment.newInstance(TYPE_CLOUD));
        fragmentList.add(MyPurseAddrListFragment.newInstance(MyPurseAddrListFragment.TYPE_LOCAl));
        titles.add("云端钱包");
        titles.add("本地钱包");
        //tabLayout.setTabMode(TabLayout.MODE_FIXED);
        viewPager.setAdapter(new BaseFragmentAdapter(getSupportFragmentManager(), fragmentList, titles));
        tabLayout.setViewPager(viewPager);
        viewPager.setOffscreenPageLimit(titles.size());
        if (isFromCloudSelect) {
            viewPager.setCurrentItem(0);
        } else if (isFromHdSelect) {
            viewPager.setCurrentItem(1);
        } else {
            viewPager.setCurrentItem(0);
        }

    }


    @Override
    public void onRightImgClicked(View v) {
        super.onRightImgClicked(v);
        Bundle bundle = new Bundle();
        bundle.putString("type", viewPager.getCurrentItem() == 0 ? TYPE_CLOUD : TYPE_LOCAl);
        launch(AddMyPurseActivity.class, bundle);
    }

    @Override
    protected void initData() {

    }


    @Override
    protected int getLayoutId() {
        return R.layout.tmperson_activity_recycler_list;
    }

    public boolean isFromHdSelect() {
        return isFromHdSelect;
    }

    public boolean isFromCloudSelect() {
        return isFromCloudSelect;
    }
}
